home *** CD-ROM | disk | FTP | other *** search
- Path: comsearch.com!tnasca
- From: Thuan Nguyen <thnguyen@comsearch.com>
- Newsgroups: comp.lang.c++
- Subject: Re: storing address of member functions, HELP!
- Date: 17 Jan 1996 22:43:55 GMT
- Organization: ComSearch, Inc
- Message-ID: <4dju3b$ehi@gateway.comsearch.com>
- References: <4djbj4$5nu@news-rocq.inria.fr>
- NNTP-Posting-Host: arcturus.comsearch.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.4 sun4c)
- X-URL: news:4djbj4$5nu@news-rocq.inria.fr
-
- Sophie.Cluet@inria.fr (Sophie Cluet) wrote:
- >Hello,
- >
- >I have a graph whose nodes represent operations and
- >whose edges indicate the operations parameters.
- >Each operation stores the address of its evaluation
- >function which is invoked through a function called
- >"evaluate" which simply evaluate the operation parameters
- >and invoke the code.
- >
- >For instance, I have:
- > Class nary_op
- > {...
- > op ** parameters; // the edges
- > int parameters_nb;
- > ...
- > int evaluate(); // evaluate the parameters and invoke
- > // the below stored function (code)
- > int (nary_op::*code)(); // address of the evaluation function
- > ...
- > int build_list(); // one such evaluation fonction
- > int and(); // another evaluation function
- > ...}
- >
- >The classes are organised in a hierarchy.
- >For instance,
- > Class struct_op: public nary_op
- > {char ** names; // added stored information
- > ...
- > int build_struct(); // an evaluation function
- > // that uses the above names
- > ...}
- >
- >
- >Now, the problem. The compiler accepts neither of the following
- >instructions on a nary_op:
- >
- > code=&struct_op::build_struct;
- > or
- > code=(int (nary_op::*)())&struct_op::build_struct;
- >
- >According to the C++ book I have, this assignment
- >not beeing type-safe is forbidden. I aggree on the
- >fact that it is not type safe, but I don't know of any
- >casting that is.
- >
- >Do you have any idea to help me out?
- >
- >Of course, I do not want to duplicate "code" or the
- >"int evaluate()" function. Also, I'd rather have as
- >little late-binding as possible when evaluating my
- >operations graph.
- >
- >Thanks in advance,
- >Sophie.
-
- Let's me try. The scope of the function is the same as the scope of the object
- itself. In code = &struct_op::build_struct; the object doesnt exist.
- How about declaring the build_struct function static.
-
- Hope this help
-
-